﻿using GatewayClient.Device;
using GatewayClient.Models;
using GatewayClient.Service;
using Iot.Device.Ads1115;
using Models.Common;
using Models.Constant;
using Newtonsoft.Json;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using UtilsBase;
using UtilsCache;
using UtilsMQ;
using UtilsMQ.Model;

namespace GatewayClient.MQ
{
    public class ServiceMQ_Helper
    {

        public bool sendMsg(MQReqModel<object> mQReqModel)
        {
            mQReqModel.gatewayTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            string input = JsonConvert.SerializeObject(mQReqModel);//JsonSerializer.Serialize< MQReqModel<object> >(mQReqModel);//

            Console.WriteLine("############################################################");
            //Console.WriteLine("网关code：" + UtilsMachineInfo.getGateWayMachineCode());
            Console.WriteLine("时间：" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").ToString());
            Console.WriteLine("推送mq推送上云:" + input);
            Console.WriteLine("############################################################");


            Debug.WriteLine("####################mqtt通道########################################");

            if (mQReqModel.respEvent == MQEventEnum.Device_Gateway_IntervalLive)
            {
                //在线状态
                new ServiceMqttClient().sendMsgRetain(input);
            }
            else
            {
                new ServiceMqttClient().sendMsg(input);
            }

            //}
            return true;
        }
    }
}
